﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Crossroad.Utils.Extensions
{
    /// <summary>
    /// 长整型类型扩展
    /// </summary>
    public static class LongExt
    {
        /// <summary>
        /// 时间戳转datetime类型
        /// </summary>
        /// <returns></returns>
        public static DateTime ToDateTime(this long input)
        {
            DateTime time = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 8, 0, 0), TimeZoneInfo.Local); // 当地时区

            return time.AddSeconds(input);
        }

        /// <summary>
        /// 时间戳转datetime类型字符串
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string ToDateTimeStr(this long input)
        {
            if (input < 1)
                return "";

            return ToDateTime(input).ToDateTimeStr();
        }

        /// <summary>
        /// 是否有内容
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Description("是否有内容 不是NULL 值不能等于0")]
        public static bool Contains(this long? input)
        {
            if (input == null)
                return false;

            return input.Value != 0L;
        }

        /// <summary>
        /// 无内容 == null || == 0
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [Description("无内容 == null || == 0")]
        public static bool NotContent(this long? input)
        {
            if (input.IsNull())
                return true;

            return input == 0L;
        }


    }
}

